﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Web;
using JXT.PrimaryKey.Batman.Core.WcfService;
using JXT.PrimaryKey.Batman.WcfService.Models;
using JXT.PrimaryKey.Batman.WcfService.Models.UserSystem;

namespace JXT.PrimaryKey.Batman.WcfService.Interfaces
{
    /// <summary>
    /// 用户相关服务接口
    /// </summary>
    [ServiceContract(Namespace = ServiceEnvironment.ServiceNamespace, Name = "user")]
    public interface IUser
    {
        /// <summary>
        /// 获取所有预设用户身份信息
        /// </summary>
        /// <returns>获取到的身份信息列表</returns>
        [OperationContract]
        [WebGet(UriTemplate = "identity/list", RequestFormat = ServiceEnvironment.WebRequestFormat, ResponseFormat = ServiceEnvironment.WebResponseFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        List<UserIdentity> GetUserIdentityList();

        /// <summary>
        /// 获取单个用户的所有信息
        /// </summary>
        /// <param name="id">用户id</param>
        /// <returns>查询到的用户信息</returns>
        [OperationContract]
        [WebGet(UriTemplate = "get/{id}", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        User GetSingle(string id);

        /// <summary>
        /// 根据用户名获取用户所有信息
        /// </summary>
        /// <param name="name">用户名</param>
        /// <returns>查询到的用户信息</returns>
        [OperationContract]
        [WebGet(UriTemplate = "get/name/{name}", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        User GetSingleByName(string name);

        /// <summary>
        /// 根据用户邮件获取用户的所有信息
        /// </summary>
        /// <param name="mail">邮件信息</param>
        /// <returns>查询到的用户信息</returns>
        [OperationContract]
        [WebGet(UriTemplate = "get/mail/{mail}", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        User GetSingleByMail(string mail);

        /// <summary>
        /// 注册新的用户
        /// </summary>
        /// <param name="user">注册用户信息</param>
        /// <returns>注册成功返回注册用户基本信息</returns>
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "register", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        BasicUser Register(RegisterUser user);

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "password/change", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        void ChangePassword(ChangedPassword password);

        /// <summary>
        /// 更新用户详细信息
        /// </summary>
        /// <param name="detail">用户详细信息</param>
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "detail/update", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        void UpdateDetail(UserDetail detail);

        /// <summary>
        /// 更新用户登录状态信息
        /// </summary>
        /// <remarks>
        /// 此方法为每次用户重新登陆之后调用
        /// </remarks>
        /// <param name="userId">用户id</param>
        /// <param name="loginIp">当前登录ip</param>
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "status/update", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        void UpdateLoginStatus(UpdatedStatus status);

        /// <summary>
        /// 查询用户名是否存在
        /// </summary>
        /// <param name="name">用户名</param>
        /// <returns>true:存在，false:不存在</returns>
        [OperationContract]
        [WebGet(UriTemplate = "name/exists/{name}", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        bool ExistsName(string name);

        /// <summary>
        /// 查询邮件地址是否存在
        /// </summary>
        /// <param name="mail">邮件地址</param>
        /// <returns>true:存在，false:不存在</returns>
        [OperationContract]
        [WebGet(UriTemplate = "mail/exists/{mail}", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        bool ExistsMail(string mail);

        /// <summary>
        /// 第三方接入登陆验证
        /// </summary>
        /// <param name="id">第三方id</param>
        /// <param name="key">第三方key</param>
        /// <returns>返回验证key</returns>
        [OperationContract]
        [WebGet(UriTemplate = "system/login/{id}/{key}", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        string SystemLogin(string id, string key);

        /// <summary>
        /// 第三方接入取消登录
        /// </summary>
        /// <param name="id">第三方id</param>
        /// <param name="key">验证key</param>
        [OperationContract]
        [WebGet(UriTemplate = "system/logout/{id}/{key}", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        void SystemLogout(string id, string key);


        [OperationContract]
        [WebGet(UriTemplate = "logout/{token}", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        void Logout(string token);


        /// <summary>
        /// 根据客户端传过来的Token,返回与该Token对应的用户数据
        /// </summary>
        /// <param name="token">验证票</param>
        /// <returns>用户对象</returns>
        [OperationContract]
        [WebGet(UriTemplate = "loginstatus/check/{token}", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        LoginUser CheckLoginStatus(string token);

        /// <summary>
        /// 获取所有用户角色列表
        /// </summary>
        /// <returns>获取所有用户角色列表</returns>
        [OperationContract]
        [WebGet(UriTemplate = "role/list", ResponseFormat = ServiceEnvironment.WebResponseFormat, RequestFormat = ServiceEnvironment.WebRequestFormat, BodyStyle = ServiceEnvironment.WebBodyStyle)]
        List<Role> GetRoleList();

    }
}
